package org.ezplatform.office.meeting.notice.web.rest;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.cloud.api.system.user.UserApiService;
import org.ezplatform.cloud.common.controller.BaseController;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.meeting.common.util.MeetingSendMsgUtils;
import org.ezplatform.office.meeting.info.entity.ApplyRecord;
import org.ezplatform.office.meeting.info.service.ApplyRecordDingService;
import org.ezplatform.office.meeting.info.service.ApplyRecordService;
import org.ezplatform.office.meeting.memo.service.MemoInfoService;
import org.ezplatform.office.meeting.notice.entity.NoticeInfo;
import org.ezplatform.office.meeting.notice.entity.NoticeTurnover;
import org.ezplatform.office.meeting.notice.service.NoticeInfoService;
import org.ezplatform.office.meeting.notice.service.NoticeTurnoverService;
import org.ezplatform.office.meeting.setting.boardroom.entity.BoardroomSet;
import org.ezplatform.office.meeting.setting.boardroom.service.BoardroomSetService;
import org.ezplatform.office.meeting.setting.serve.service.ServeSetService;
import org.ezplatform.util.DateUtils;
import org.ezplatform.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *会议管理--会议通知
 *
 */
@RestController
@RequestMapping("api/meeting/noticeInfo")
public class NoticeInfoApiController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(NoticeInfoApiController.class);
    
    @Autowired
	private ApplyRecordService applyRecordService;
    
    @Autowired
	private NoticeTurnoverService noticeTurnoverService;
    
    @Autowired
    private NoticeInfoService noticeInfoService;
    
    @Autowired
    private ApplyRecordDingService applyRecordDingService;

    @Autowired
    private MemoInfoService memoInfoService;
    
    @Autowired
	private UserApiService userApiService;
    
    @Autowired
    private BoardroomSetService boardroomSetService;
	
	@Autowired
	private MeetingSendMsgUtils meetingSendMsgUtils;
    
	@Autowired
	private ServeSetService serveSetService;
	
	/**
	 * 会议通知数量接口
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/meetingNoticeNum", method=RequestMethod.GET, produces={"application/json; charset=UTF-8"})
    public OperationResult meetingNoticeNum(HttpServletRequest request){
		String corpId=request.getParameter("corpId");
		String userId=request.getParameter("userId");
        int noticeListNum = noticeInfoService.getNoticeListNum(corpId, userId);
        Map<String,String> m = new HashMap<String,String>();
        
        m.put("count", noticeListNum+"");
        return OperationResult.buildSuccessResult(m);
	}
	
    /**
     * 会议通知
     */
    @ApiOperation(value="会议通知", notes="查询我参加会议的会议通知list列表数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/attendNoticeInfoSetList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getAttendNoticeInfoSetList(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition");
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");
            String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
            //查询会议通知列表数据
            List<Map> list = this.noticeInfoService.getNoticeInfoSetList(currentPage, pageSize,userId,corpId,"0",condition,1,nowDateTime);
            //查询会议申请列表数count
            int approvalCount = this.noticeInfoService.getNoticeInfoSetListCount(userId,corpId,"1","",0,nowDateTime);
            //查询会议纪要未读列表数count
            int memoCount = this.memoInfoService.getMemoInfoListCount(userId, corpId);
            map.put("data", list);
            map.put("approvalCount", approvalCount);
            map.put("memoCount", memoCount);
            map.put("currentPage", Integer.parseInt(currentPage));
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 会议通知
     */
    @ApiOperation(value="会议通知", notes="查询我审批会议的会议通知list列表数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "page", value = "当前显示页数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pageSize", value = "一页显示数", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "condition", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/approvalNoticeInfoSetList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getApprovalNoticeInfoSetList(HttpServletRequest request) {
    	Map<String,Object> map = new HashMap<String,Object>();
        try{
            //当前页
            String currentPage = request.getParameter("page");
            //一页显示条数
            String pageSize = request.getParameter("pageSize");
            //查询条件
            String condition = request.getParameter("condition");
            //用户ID
            String userId = request.getParameter("userId");
            //用户单位
            String corpId = request.getParameter("corpId");

            String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm:ss");
            List<Map> list = this.noticeInfoService.getNoticeInfoSetList(currentPage, pageSize,userId,corpId,"0",condition,0,nowDateTime);
            //查询会议申请列表数count
            //int approvalCount = this.noticeInfoDingService.getNoticeInfoSetListCount(userId,corpId,"1","",0,nowDateTime);
            //查询会议纪要未读列表数count
            //int memoCount = this.memoInfoService.getMemoInfoListCount(userId, corpId);
            map.put("data", list);
            //map.put("approvalCount", approvalCount);
            //map.put("memoCount", memoCount);
            map.put("currentPage", Integer.parseInt(currentPage));
        }catch(Exception e){
            e.printStackTrace();
            return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 会议通知详细页面数据
     * @param request
     * @return
     */
    @ApiOperation(value="会议通知", notes="查看会议通知详细信息")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "type", value = "0-审批通知，1-参会通知", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "id", value = "会议通知id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/attendNoticeInfo", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getAttendNoticeInfo(HttpServletRequest request) {
        Map<String,Object> map = new HashMap<String,Object>();
        try{
            String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            String userId = request.getParameter("userId");
            String applyRecordId = request.getParameter("id");
            String type = StringUtils.null2String(request.getParameter("type"));
            if(type == ""){
            	type = "1";
            }
            String nStatus = "";
            ApplyRecord applyRecord = this.applyRecordDingService.findOne(applyRecordId);
            if(applyRecord == null) {
            	map.put("isDeleted", true);
            	return OperationResult.buildSuccessResult(map);
            }
        	map.put("isDeleted", false);
        	List<Map> serveSetCheckList = new ArrayList<Map>();//会议申请选中的会议服务
        	BoardroomSet boardroomSet = null;
			String boardroomId = applyRecord.getBoardroomId();
			if(StringUtils.isNotEmpty(boardroomId)) {
				boardroomSet = this.boardroomSetService.findOne(boardroomId);
			}
			serveSetCheckList = this.serveSetService.getServeSetCheckList(applyRecord.getMeetingServe());
			//发起人
			String createdBy = applyRecord.getCreatedBy();
			Map<String, Object> userMap = this.userApiService.getUser(createdBy, corpId, "", token);
			map.put("createdName", userMap != null ? userMap.get("userName") : "");
			map.put("applyRecord", applyRecord);
        	map.put("serveSetCheckList", serveSetCheckList);
        	map.put("boardroomSet", boardroomSet);
        	boolean needPostionSigned = false, needQrcodeSigned = false;
        	String signedDateTime = "";
        	if(applyRecord.getIsSigned() == 1) {
        		List<String> meetingUserIdList = this.applyRecordService.getApplyRecordUserList(applyRecord, token);
            	if(meetingUserIdList.contains(userId)) {//是参会人员
            		if("0".equals(applyRecord.getSignedType())) needQrcodeSigned = true;
            		else if("1".equals(applyRecord.getSignedType())) needPostionSigned = true;
            		else if("2".equals(applyRecord.getSignedType())) {
            			needQrcodeSigned = true;
            			needPostionSigned = true;
            		}
            	}
				String startDateTime = applyRecord.getStartTime();
				String signedTime = applyRecord.getSignedTime();
				String signedTimeStr = this.getDateTimeStr(startDateTime.substring(11, 16), Integer.valueOf(signedTime), 1);
				signedDateTime = startDateTime.substring(0,10)+" "+signedTimeStr+":00";
        	}
        	map.put("needPostionSigned", needPostionSigned);
        	map.put("needQrcodeSigned", needQrcodeSigned);
        	map.put("signedDateTime", signedDateTime);
            //会议通知数据处理
            NoticeInfo noticeInfo = new NoticeInfo();
            noticeInfo = this.noticeInfoService.findByApplyrecordId(applyRecordId, userId, type);
            List<NoticeTurnover> ntList = this.noticeTurnoverService.findNoticeTurnoverList(applyRecordId, userId, corpId);
//            map = this.applyRecordDingService.getApproveApplyRecordContent(applyRecordId,corpId,token);
            if(ntList != null && ntList.size() > 0) map.put("isTurnover", true);
            else map.put("isTurnover", false);
            int isSigned = applyRecord.getIsSigned();
            if(noticeInfo != null){
            	int status = noticeInfo.getStatus();
                if(status==0){
                    nStatus = "0";
                }else{
                    nStatus = "2";
                    if(isSigned==1){
                        nStatus = "1";
                    }
                }
            }
            map.put("noticeInfo", noticeInfo);
            map.put("nStatus",nStatus);
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(map);
    }
    
    /**
     * 转本部门
     */
    @ApiOperation(value = "转本部门", notes = "转本部门")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "userName", value = "用户姓名", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "id", value = "会议通知ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "meetingId", value = "会议ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "jsonStrReceiveUser", value = "接收人", required = false, paramType = "body", dataType = "String")
        })
    @RequestMapping(value = "/saveTurnoverInfo", method = RequestMethod.POST)
    public OperationResult saveTurnoverInfo(HttpServletRequest request) {
        logger.debug("转本部门开始");
        try{
        	String corpId = request.getParameter("corpId");
            String token = request.getParameter("token");
            String userId = request.getParameter("userId");
            String userName = request.getParameter("userName");
            String noticeInfoId = StringUtils.null2String(request.getParameter("id"));
            String applyRecordId = StringUtils.null2String(request.getParameter("meetingId"));
            String jsonStrReceiveUser = StringUtils.null2String(request.getParameter("jsonStrReceiveUser"));
    		String receiveUserId = "";
    		String receiveUserName = "";
    		String turnoverUserId = userId;
    		NoticeTurnover entity = new NoticeTurnover();
    		entity.setApplyRecordId(applyRecordId);
    		entity.setNoticeInfoId(noticeInfoId);
    		if(!"".equals(jsonStrReceiveUser)) {
    			Map<String, String> map = getUserId(jsonStrReceiveUser);
    			receiveUserId = map.get("id");
    			receiveUserName = map.get("name");
    			if(turnoverUserId.equals(receiveUserId)) {
    				return OperationResult.buildFailureResult("接收人不能选自己");
    			}
    			if(noticeTurnoverService.findByApplyrecordId(entity.getApplyRecordId(), receiveUserId, corpId) != null) {
    				return OperationResult.buildFailureResult("该用户已转交他人代替参会，请重新选择");
    			}
    			entity.setReceiveUserId(receiveUserId);
    			entity.setReceiveUserName(map.get("name"));
    		}
    		entity.setTurnoverUserId(turnoverUserId);
    		entity.setTurnoverUserName(userName);
    		ApplyRecord ar = applyRecordService.findOne(applyRecordId);
    		//主持人或纪要员或参与人替换
    		noticeTurnoverService.changeUser(ar, token, turnoverUserId, receiveUserId, receiveUserName);
    		//通知状态改为4
    		NoticeInfo ni = noticeInfoService.findOne(entity.getNoticeInfoId());
    		ni.setStatus(4);
    		ni.setReason(null);
    		noticeInfoService.save(ni);
    		//查询所有参会人
    		List<String> aruList = applyRecordService.getApplyRecordUserList(ar, token);
    		if(aruList.contains(receiveUserId)) {
    			//转交人是已参会人员，就不用新建通知数据
    			NoticeInfo noticeInfo = this.noticeInfoService.findByApplyrecordId(entity.getApplyRecordId(), receiveUserId, "1");
    			if(noticeInfo != null && StringUtils.isNotEmpty(noticeInfo.getId())) {
    				noticeInfo.setStatus(5);
    				noticeInfoService.save(ni);
    			}
    		}else{
    			//转交人可查看通知，新建转交人通知数据
    			NoticeInfo receiveNi = new NoticeInfo();
    			receiveNi.setStatus(5);
    			receiveNi.setApplyRecordId(ni.getApplyRecordId());
    			receiveNi.setType(ni.getType());
    			receiveNi.setNoticeUserId(receiveUserId);
    			noticeInfoService.save(receiveNi);
    		}
    		this.sendMessageToTurnoverUser(request, ar, userId, receiveUserId, corpId, token);
    		noticeTurnoverService.save(entity);
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("转本部门失败");
        }
        logger.debug("转本部门结束");
        return OperationResult.buildSuccessResult("转本部门成功");
    }
    
    /**
     * 数据提交前校验
     */
    @ApiOperation(value = "数据提交前校验", notes = "数据提交前校验")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "meetingId", value = "会议ID", required = true, paramType = "query", dataType = "String"),
        })
    @RequestMapping(value = "/checkTurnoverDate", method = RequestMethod.GET)
    public OperationResult checkTurnoverDate(HttpServletRequest request) {
    	String corpId = request.getParameter("corpId");
        String turnoverUserId = request.getParameter("userId");
        String applyRecordId = StringUtils.null2String(request.getParameter("meetingId"));
		ApplyRecord ar = applyRecordService.findOne(applyRecordId);
		if(ar == null) {
			return OperationResult.buildFailureResult("当前数据已删除");
		}
		if(noticeTurnoverService.findByApplyrecordId(applyRecordId, turnoverUserId, corpId) != null) {
			return OperationResult.buildFailureResult("该会议您已转交他人");
		}
        return OperationResult.buildSuccessResult();
    }
    
    /**
     * 给转交人推送消息
     * @param request
     * @param entity
     * @param userId
     * @param corpId
     */
    private void sendMessageToTurnoverUser(HttpServletRequest request, ApplyRecord entity, String sendUserId, String turnoverUserId, String corpId, String token) {
    	Map<String, Object> ds = new HashMap<>();
        ds.put("applyRecordId", entity.getId());
 		ds.put("meetingTitle", entity.getName());
 		ds.put("startTime", entity.getStartTime());
 		BoardroomSet room = this.boardroomSetService.findOne(entity.getBoardroomId());
 		if(room != null) ds.put("boardroom", room.getAddress());
        String userName = "";
        Map<String, Object> userInfo = this.userApiService.getUser(sendUserId, corpId,  "", TOKEN);
        if(userInfo != null){
            userName = StringUtils.null2String(userInfo.get("userName"));
        }
 		ds.put("userId", sendUserId);
 		ds.put("userName", userName);
 		ds.put("userOrg", "");
 		ds.put("type", "8");
 		ds.put("userIds", turnoverUserId);
        ds.put("orgIds", null);
        boolean mobilePush = false;
        boolean emailPush = false;
        boolean smsPublish = false;
		String mesgPush = entity.getMessagePush();
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
		if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
		this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, TOKEN);
        this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
		this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
        String jsonIds = "[{\"10\":\"" + turnoverUserId + "\"}]";
        this.meetingSendMsgUtils.sendMessage(ds, jsonIds, corpId, token);
    }
    
    /**
	 * 根据选人组件(单选)json获取id,name
	 * @param jsonStr
	 * @return
	 */
	private Map<String, String> getUserId(String jsonStr) {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray json = (JSONArray) JSONArray.parse(jsonStr);
	    if(json != null && json.size() > 0) {
	    	JSONObject jo = (JSONObject)json.get(0);
	    	map.put("id", jo.getString("scopeValue"));
	    	map.put("name", jo.getString("scopeName"));
	    }
	    return map;
	}
    
    /**
     * 修改修改会议通知状态
     */
    @ApiOperation(value = "修改会议通知状态", notes = "确认参会、请假")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "会议通知ID", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "status", value = "1:确认参会 2:请假 ", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "reason", value = "请假原因 ", required = false, paramType = "body", dataType = "String")
        })
    @RequestMapping(value = "/editNoticeInfo", method = RequestMethod.POST)
    public OperationResult editNoticeInfo(HttpServletRequest request) {
        logger.debug("保存会议通知状态信息开始");
        // String corpId = WebUtils.getCurrentUser().getCorpId();

        try {
            String id =  request.getParameter("id");
            String status =  request.getParameter("status");
            String reason =  request.getParameter("reason");
            
            if("1".equals(status)){
                this.noticeInfoService.editNoticeInfo(id,2,reason);
            }else if("2".equals(status)){
                this.noticeInfoService.editNoticeInfo(id,3,null);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return OperationResult.buildFailureResult("保存会议通知状态失败");
        }
        logger.debug("保存会议通知状态结束");
        return OperationResult.buildSuccessResult("保存会议通知状态成功");
    }
    
    public String getRequestPayload(HttpServletRequest req) {
        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = req.getReader();
            Throwable localThrowable3 = null;
            try {
                char[] buff = new char[1024];
                int len;
                while ((len = reader.read(buff)) != -1)
                    sb.append(buff, 0, len);
            } catch (Throwable localThrowable1) {
                localThrowable3 = localThrowable1;
                throw localThrowable1;
            } finally {
                if (reader != null)
                    if (localThrowable3 != null)
                        try {
                            reader.close();
                        } catch (Throwable localThrowable2) {
                            localThrowable3.addSuppressed(localThrowable2);
                        }
                    else
                        reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return sb.toString();
    }

    /**
     * 计算有效时间
     * @param dateTime
     * @param data
     * @param type
     * @return
     */
    public String getDateTimeStr(String dateTime, int data,int type) {
        String hourStr = "";
        String minStr = "";
        String[] arr = dateTime.split(":");
        int hour =Integer.valueOf(arr[0]);
        int min = Integer.valueOf(arr[1]);
        if(type==0){//相加计算
            hour = hour + (data+min)/60;
            min =(data+min)-(data+min)/60*60;
        }else if(type==1){//相减计算
            for(int i=0;i<hour;i++){
                if(((i*60+min)-data)>0){
                    hour = (hour-i);
                    min = (i*60+min)-data;
                    break;
                }
            }
        }
        if(hour<10){
            hourStr = "0" + hour;
        }else{
            hourStr = "" + hour;
        }
        if(min<10){
            minStr = "0" + min;
        }else{
            minStr = "" + min;
        }
        return hourStr + ":"+ minStr;
    }
    
    /**
     * 发送提醒功能
     */
    @ApiOperation(value = "发送提醒功能", notes = "发送提醒")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "applyRecordId", value = "会议ID", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userId", value = "用户ID ", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userName", value = "用户名 ", required = false, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "org", value = "组织id ", required = false, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "corpId", value = "corpId", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "token", value = "token ", required = true, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "context", value = "发送内容 ", required = false, paramType = "body", dataType = "String"),
        @ApiImplicitParam(name = "userArrays", value = "接收人 ", required = false, paramType = "body", dataType = "String"),
        })
    @RequestMapping(value = "/sendMeetingRemind", method = RequestMethod.POST)
    public OperationResult sendMeetingRemind(HttpServletRequest request) {
    	try {
    		String applyRecordId = request.getParameter("applyRecordId");
    		ApplyRecord applyRecord = applyRecordService.findOne(applyRecordId);
    		String userId = request.getParameter("userId");
    		String userName = request.getParameter("userName");
    		String userOrg = request.getParameter("org");
    		String corpId = request.getParameter("corpId");
    		String token = request.getParameter("token");
    		String context = request.getParameter("context");
    		String userArrays = request.getParameter("userArrays");
    		Map<String, Object> ds = new HashMap<>();
            ds.put("applyRecordId", applyRecordId);
            if(applyRecord != null) {
            	ds.put("meetingTitle", applyRecord.getName());
            }else {
            	ds.put("meetingTitle", "");
            }
     		ds.put("meetingRemindContext", context);
     		ds.put("userId", userId);
     		ds.put("userName", userName);
     		ds.put("userOrg", userOrg);
     		ds.put("type", "10");
     		ds.put("userIds", userArrays);
            ds.put("orgIds", null);
            boolean mobilePush = false;
            boolean emailPush = false;
            boolean smsPublish = false;
			String mesgPush = applyRecord.getMessagePush();
			if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("mobile")) mobilePush = true;
			if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("email")) emailPush = true;
			if(StringUtils.isNotEmpty(mesgPush) && mesgPush.contains("sms")) smsPublish = true;
    		this.meetingSendMsgUtils.sendMail(ds, emailPush, corpId, TOKEN);
            this.meetingSendMsgUtils.sendMsgToApp(ds, mobilePush, corpId, token, request);
			this.meetingSendMsgUtils.sendSMS(ds, smsPublish, corpId, token);
            String jsonIds = "[";
            if(StringUtils.isNotEmpty(userArrays)) {
            	String[] userIds = userArrays.split(",");
            	for(String ids : userIds) {
            		jsonIds += "{\"10\":\"" + ids + "\"}";
            	}
            }
            jsonIds += "]";
            this.meetingSendMsgUtils.sendMessage(ds, jsonIds, corpId, token);
		} catch (Exception e) {
			return OperationResult.buildFailureResult("发送失败");
		}
    	return OperationResult.buildSuccessResult("发送成功");
    }
    
    //++++++++++++++++++++++++++++++++++++++++++++++++++++以下对外api
    
    /**
     * 会议通知
     */
    @ApiOperation(value="会议通知PC门户", notes="查询我参加会议的会议通知list列表数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "type", value = "0.审批,1.参会通知,2.审批和参会通知", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "showNumber", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/getNoticeInfoListToPortlet", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getNoticeInfoListToPortlet(HttpServletRequest request) {
    	List<Map> list = new ArrayList<Map>();
        try{
            //显示条数
            String showNumber = request.getParameter("showNumber");
            String corpId = request.getParameter("corpId");
            String userId = request.getParameter("userId");
            //String type = request.getParameter("type");
            //String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
            //list= this.noticeInfoService.getNoticeInfoSetList2(corpId,"",userId,nowDateTime,showNumber,type);
            //list= this.noticeInfoService.getNoticeListMenHu(corpId, userId, showNumber);
            
            list= this.noticeInfoService.getNoticeListMenHu_new(corpId, userId, showNumber);
            
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(list);
    }
    
    /**
     * 会议通知
     */
    @ApiOperation(value="会议通知移动端门户", notes="查询我参加会议的会议通知list列表数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "type", value = "0.审批,1.参会通知,2.审批和参会通知", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "showNumber", value = "查询条件", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/getNoticeInfoList", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getNoticeInfoList(HttpServletRequest request) {
    	List<Map> list = new ArrayList<Map>();
        try{
            //显示条数
            String showNumber = request.getParameter("showNumber");
            String corpId = request.getParameter("corpId");
            String userId = request.getParameter("userId");
            String type = request.getParameter("type");
            String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm");
            list= this.noticeInfoService.getNoticeInfoList(corpId,"",userId,nowDateTime,showNumber,type);
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(list);
    }
    
    /**
     * 会议通知数量
     */
    @ApiOperation(value="会议通知数量", notes="查询参会邀请和会议审批数量")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "userId", value = "当前用户ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "corpId", value = "单位ID", required = true, paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "type", value = "0.审批,1.参会通知,2.审批和参会通知", required = true, paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/getNoticeInfoCount", method = RequestMethod.GET,produces={"application/json; charset=UTF-8"})
    public OperationResult getNoticeInfoCount(HttpServletRequest request) {
        int count = 0;
    	try{
            String corpId = request.getParameter("corpId");
            String userId = request.getParameter("userId");
            String type = request.getParameter("type");
            String nowDateTime = DateUtils.formatDate(DateUtils.now(),"yyyy-MM-dd HH:mm:ss");
            count = this.noticeInfoService.getNoticeInfotCount(userId, corpId, nowDateTime, type);
        }catch(Exception e){
        	e.printStackTrace();
        	return OperationResult.buildFailureResult("获取失败");
        }
        return OperationResult.buildSuccessResult(count);
    }
}